package com.uit.gis.pojo;

import com.uit.gis.util.JsonData;
import com.uit.gis.util.Util.SpatialType;

import processing.data.JSONObject;

public class Box extends Shape {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	JSONObject boxObj ;
	int boxW = 100;
	int boxH = 100;
	int boxD = 100;
	int boxX, boxY;
	int clickCount = 0;
	 

	public void setup() {
		 background(255);
		boxObj = new JSONObject();
	    size(super.width, super.height, P3D);
	    spatialType = SpatialType.BOX;
	    
	}
	public void draw() {
	  if (clickCount == 1) {
	    background(255);
	    boxX = mouseX;
	    boxY = mouseY;
	    translate(boxX, boxY);
	    stroke(0);
	    noFill();
	    box(boxW, boxH, boxD);
	  }
	}

	public void mousePressed() {
	    if (clickCount == 0) {
	      clickCount++;
	    } else {
	      clickCount = 0;
	    }
	}

//	public void keyPressed() {
//	    boxObj.setInt("w", boxW);
//	    boxObj.setInt("h", boxH);
//	    boxObj.setInt("d", boxD);
//	    boxObj.setInt("x", boxX);
//	    boxObj.setInt("y", boxY);
//	    saveJSONObject(boxObj, "box.json");
//	    //exit();
//	}
	@Override
	public void mouseClicked(processing.event.MouseEvent e) {
		if (e.getButton() == processing.core.PConstants.RIGHT) {
			   boxObj.setInt("w", boxW);
			    boxObj.setInt("h", boxH);
			    boxObj.setInt("d", boxD);
			    boxObj.setInt("x", boxX);
			    boxObj.setInt("y", boxY);
			    saveToTextFile();
		} 
	}
	@Override
	public void saveToTextFile() {
		// TODO Auto-generated method stub
		saveJSONObject(boxObj,  getSavingPath());
		super.saveToTextFile();
	}
	@Override
	public JsonData loadDataFromFile() {
		// TODO Auto-generated method stub
		JSONObject jsonObject = loadJSONObject(getSavingPath());
		JsonData jsonData = new JsonData(null, jsonObject);
		return jsonData;
	}
	 
}
